/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLELF_SYMBOL_TABLE64_H
#define PLELF_SYMBOL_TABLE64_H

#include <elf/plelfsymboltableenum.h>
#include <elf/plelfstddef.h>

namespace PLSDK {

#define PLELF64_ST_BIND(i)   ((i) >> 4)
#define PLELF64_ST_TYPE(i)   ((i) &  0xf)
#define PLELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))

#define PLELF64_ST_VISIBILITY(o) ((o) & 0x3)

/**
 * An object file's symbol table holds information needed to locate and relocate
 * a program's symbolic definitions and references. A symbol table index is a
 * subscript into this array. Index 0 both designates the first entry in the table
 * and serves as the undefined symbol index. The contents of the initial entry
 * are specified later in this section.
 */
class PLELFSymbolTable64 : public PLELFSymbolTableEnum {
public:
	/**
	 * Constructor.
	 */
	PLELFSymbolTable64() {}
	/**
	 * Get the symbol binding from the symbol table.
	 *
	 * @return The symbol binding type.
	 */
	inline PLELFSymbolTable64::STInfoBinding infoSymbolBinding();
	/**
	 * Get the symbol types from the symbol table.
	 *
	 * @return The symbol types type.
	 */
	inline PLELFSymbolTable64::STInfoTypes infoSymbolTypes();
	/**
	 * Get the visibility of the symbol table.
	 *
	 * @return The visibility table.
	 */
	inline PLELFSymbolTable64::STInfoVisibility otherSymbolVisibility();
	/**
	 * This member holds an index into the object file's symbol string table,
	 * which holds the character representations of the symbol names. If the value
	 * is non-zero, it represents a string table index that gives the symbol name.
	 * Otherwise, the symbol table entry has no name.
	 */
	Elf64_Word    st_name;
	/**
	 * This member specifies the symbol's type and binding attributes.
	 */
	unsigned char st_info;
	/**
	 * This member currently specifies a symbol's visibility. 
	 */
	unsigned char st_other;
	/**
	 * Every symbol table entry is defined in relation to some section. This member holds
	 * the relevant section header table index. As the sh_link and sh_info interpretation
	 * table and the related text describe, some section indexes indicate special meanings.
	 */
	Elf64_Half    st_shndx;
	/**
	 * This member gives the value of the associated symbol. Depending on the
	 * context, this may be an absolute value, an address, and so on; details appear below.
	 */
	Elf64_Addr    st_value;
	/**
	 * Many symbols have associated sizes. For example, a data object's size is the number
	 * of bytes contained in the object. This member holds 0 if the symbol has no size or
	 * an unknown size.
	 */
	Elf64_Xword    st_size;
} __attribute__((packed));

PLELFSymbolTable64::STInfoBinding PLELFSymbolTable64::infoSymbolBinding() {
	return (PLELFSymbolTable64::STInfoBinding)PLELF64_ST_BIND(st_info);
}

PLELFSymbolTable64::STInfoTypes PLELFSymbolTable64::infoSymbolTypes() {
	return (PLELFSymbolTable64::STInfoTypes)PLELF64_ST_TYPE(st_info);
}

PLELFSymbolTable64::STInfoVisibility PLELFSymbolTable64::otherSymbolVisibility() {
	return (PLELFSymbolTable64::STInfoVisibility)st_other;
}

}

#endif
